<?php
if (isset($_POST['excluir'])) {
    require_once ("../controller/fornecedorController.php");
    $control = new fornecedorController();
    $model = $control->getModel();
    $model->setId($_POST['excluir']);

    $redirecionar = "../view/fornecedorConsultar.php";

    if ($control->deleteDados($model) == true) {
        header("location:" . $redirecionar . "");
    }
}
?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html lang="pt-br">
    <head>
        <title>Consultar Fornecedor</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width">
        <link href="../css/TemplateTelaConsulta.css" rel="stylesheet" type="text/css" />
        <link href="../css/TemplateMenu.css" rel="stylesheet" type="text/css" />

    </head>
    <body>
        <?php
        $url = "../";
        include '../template/topoView.php';
        ?>

        <?php
        include '../template/menuView.php';
        ?>

        <div id="meio">
            <div > 
                <div >
                    <form method="post">
                        <table >
                            <tr>
                                <td valign="middle">
                                    <b style="font-size: 30px">Pesquisar Fornecedor:</b>
                                </td>
                                <td valign="middle"> 
                                    <input type="text" name="nomePesquisar" autofocus="true" size="30" maxlength="50" style="height: 25px;"/>
                                </td>
                                <td valign="middle">
                                    <button type="submit" name="pesquisar">
                                        <?php
                                        echo " <img src=" . $url . "imagem/search_icon.png width='20px' height='20px'/>";
                                        ?>
                                    </button>
                                </td>
                            </tr>
                        </table>
                    </form>
                    <hr>
                    <table border="3">
                        <tr>
                            <th>Código</th>
                            <th>Nome</th>
                            <th>CNPJ</th>
                            <th>Telefone</th>
                            <th>Editar</th>
                            <th>Excluir</th>
                        </tr>
                        <?php
                        require_once '../controller/fornecedorController.php';
                        $control = new fornecedorController();
                        $model = $control->getModel();
                        if (isset($_POST['pesquisar'])) {
                            $model->setNome($_POST['nomePesquisar']);
                        }
                        $resultado = $control->getDados($model);
                        while ($escrever = mysql_fetch_array($resultado)) {
                            ?>
                            <tr>
                                <td align="center"  width="100px"><?php echo $escrever["ID_PK"]; ?> </td>
                                <td align="left" width="450px"><?php echo $escrever["NOME"]; ?> </td>
                                <td align="center" width="200px"><?php echo $escrever["CNPJ"]; ?> </td>
                                <td align="center" width="150px"><?php echo $escrever["TELEFONE"]; ?> </td>
                                <td align="center">
                                    <form action="fornecedorCadastrar.php" method="post">
                                        <button type="submit" name="editar" value="<?php echo $escrever["ID_PK"] ?>">
                                            <img src="../imagem/edit_icon.png" width="20px" height="20px"/> 
                                        </button>
                                    </form>
                                </td>
                                <td align="center">
                                    <form method="post">
                                        <button type="submit" name="excluir" value="<?php echo $escrever["ID_PK"] ?>">
                                            <img src="../imagem/delete_icon.png" width="20px" height="20px"/> 
                                        </button>
                                    </form>
                                </td>
                            </tr>
                        <?php } ?>
                    </table>
                    <hr>
                    <a href="fornecedorCadastrar.php">
                        <img src="../imagem/add_icon.png" width="20px" height="20px">Novo
                    </a>
                </div> 
            </div>
        </div> 
        <?php
        include '../template/rodapeView.php';
        ?>
    </div>

</body>
</html>

